import File from './File';
import Context from '../Context';
import { appendExt, joinPath } from '../Utils';
import { TemplateRenderer } from '../Types';

export default class TemplateFile extends File {
    public readonly type: FileType = FileType.template;
    public render?: TemplateRenderer;

    constructor(cx: Context, op: CreateFileOptions, render?: TemplateRenderer) {
        super(cx, op);
        this.render = render;
    }

    public async doLoad() {
        this.loadContents();
        if (this.render) {
            this.contents = await this.render(this.contents, {
                path: this.getVinylFilePath(),
                id: this.id,
                options: this.cx.options
            });
        }
    }
}